using com.youzu.warh.protocol;
using CustomDataStruct;
using ProtoBuf.Serializers;

namespace battle
{
    public class TroopFightInfoDecorator: ICustomProtoSerializer
    {
        public void SetValue(object target, object value, int fieldNumber)
        {
            TroopFightInfo data = target as TroopFightInfo;
            if (data == null)
            {
                return;
            }
            switch (fieldNumber)
            {
                case 1:
                    data.troop = (MapUnit) value; 
                    break;
                case 2:
                    data.skills.Add((CastSkill)value);
                    break;
                case 3:
                    data.rage = ValueObject.Value<int>(value);
                    break;
                case 4:
                    data.coordinate = (Coordinate) value;
                    break;
                case 5:
                    data.soldiers.Add(ValueObject.Value<int>(value));
                    break;
                case 6:
                    data.intSoldierNum = ValueObject.Value<int>(value);
                    break;
                case 7:
                    data.curSoldierNum = ValueObject.Value<int>(value);
                    break;
                case 8:
                    data.elements.Add((EffectElement)value);
                    break;
                case 9:
                    data.besiege =  ValueObject.Value<int>(value);
                    break;
                case 10:
                    data.playerId = ValueObject.Value<long>(value);
                    break;
                case 11:
                    data.besiegePlayerId.Add(ValueObject.Value<long>(value));
                    break;
                case 12:
                    data.speed = ValueObject.Value<float>(value);
                    break;
                case 13:
                    data.isFightOver = ValueObject.Value<bool>(value);
                    break;
                case 14:
                    data.normalDamage.Add((CastDamage)value);
                    break;
                case 15:
                    data.passiveDamage.Add((CastDamage)value);
                    break;       
                case 16:
                    data.rageHeroIndex =  ValueObject.Value<int>(value);
                    break;
                case 17:
                    data.isAttackIntent = ValueObject.Value<bool>(value);
                    break;
            }
        }

        public object GetValue(object target, int fieldNumber)
        {
            TroopFightInfo data = target as TroopFightInfo;
            if (data == null)
            {
                return null;
            }

            switch (fieldNumber)
            {
                case 1:
                    return data.troop;
                case 2:
                    return data.skills;
                case 3:
                    return ValueObject.Get(data.rage);
                case 4:
                    return data.coordinate;
                case 5:
                    return data.soldiers;
                case 6:
                    return ValueObject.Get(data.intSoldierNum);
                case 7:
                    return ValueObject.Get(data.curSoldierNum);
                case 8:
                    return data.elements;
                case 9:
                    return ValueObject.Get(data.besiege);
                case 10:
                    return ValueObject.Get(data.playerId);
                case 11:
                    return data.besiegePlayerId;
                case 12:
                    return ValueObject.Get(data.speed);
                case 13:
                    return ValueObject.Get(data.isFightOver);
                case 14:
                    return data.normalDamage;
                case 15:
                    return data.passiveDamage;
                case 16:
                    return data.rageHeroIndex;
                case 17:
                    return data.isAttackIntent;
            }
            
            return null;
        }
    }
}